
package helpdesk;

import database.*;
import java.util.ArrayList;
import logindata.User;

public class GradAssCoordInterface extends CenteredFrame {

    public GradAssCoordInterface() {
        initComponents();
        currentUser = "hidden";
    }

    public GradAssCoordInterface(String User) {
        initComponents();
        currentUser = User;
        updateUserList();
    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        editQueryFrame = new CenteredFrame();
        jScrollPane4 = new javax.swing.JScrollPane();
        editQueryTextArea = new javax.swing.JTextArea();
        submitEditQueryBtn = new javax.swing.JButton();
        StudentEditFrame = new CenteredFrame();
        jScrollPane5 = new javax.swing.JScrollPane();
        UsersList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        usernameBox = new javax.swing.JTextField();
        passwordBox = new javax.swing.JTextField();
        permissionsBox = new javax.swing.JTextField();
        updateUserInfoButton = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        getUserInfoButton = new javax.swing.JButton();
        editAnnouncementFrame = new CenteredFrame();
        jScrollPane6 = new javax.swing.JScrollPane();
        editAnnouncementTextArea = new javax.swing.JTextArea();
        btn_Submit = new javax.swing.JButton();
        viewAvailability = new CenteredDialog();
        jLabel7 = new javax.swing.JLabel();
        select_Cmb = new javax.swing.JComboBox();
        dayDropDown = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jScrollPane8 = new javax.swing.JScrollPane();
        hoursList = new javax.swing.JList();
        queRespFrame = new CenteredDialog();
        jScrollPane7 = new javax.swing.JScrollPane();
        viewQueRespTextArea = new javax.swing.JTextArea();
        jScrollPane9 = new javax.swing.JScrollPane();
        submitQueRespTextArea = new javax.swing.JTextArea();
        submitQueRespBtn = new javax.swing.JToggleButton();
        submitBtn = new javax.swing.JButton();
        optionsPanel = new javax.swing.JPanel();
        stuRoleBtn = new javax.swing.JButton();
        rplyQueryBtn = new javax.swing.JButton();
        editQueryBtn = new javax.swing.JButton();
        deleteQueryBtn = new javax.swing.JButton();
        editAnnounceBtn = new javax.swing.JButton();
        deleteAnnounceBtn = new javax.swing.JButton();
        viewAvaBtn = new javax.swing.JButton();
        jScrollPane2 = new javax.swing.JScrollPane();
        submissionTextArea = new javax.swing.JTextArea();
        announcementsScrollPane = new javax.swing.JScrollPane();
        announcementsTable = new javax.swing.JTable();
        queriesScrollPane = new javax.swing.JScrollPane();
        queriesTable = new javax.swing.JTable();

        editQueryTextArea.setColumns(20);
        editQueryTextArea.setLineWrap(true);
        editQueryTextArea.setRows(5);
        editQueryTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Edit Query"));
        jScrollPane4.setViewportView(editQueryTextArea);

        submitEditQueryBtn.setText("Update");
        submitEditQueryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitEditQueryBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout editQueryFrameLayout = new org.jdesktop.layout.GroupLayout(editQueryFrame.getContentPane());
        editQueryFrame.getContentPane().setLayout(editQueryFrameLayout);
        editQueryFrameLayout.setHorizontalGroup(
            editQueryFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(editQueryFrameLayout.createSequentialGroup()
                .add(35, 35, 35)
                .add(editQueryFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(submitEditQueryBtn)
                    .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 506, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        editQueryFrameLayout.setVerticalGroup(
            editQueryFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(editQueryFrameLayout.createSequentialGroup()
                .add(28, 28, 28)
                .add(jScrollPane4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(submitEditQueryBtn)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        jScrollPane5.setViewportView(UsersList);

        jLabel1.setText("Username:");

        jLabel2.setText("Password:");

        jLabel3.setText("Permissions:");

        updateUserInfoButton.setText("Update User Info");
        updateUserInfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                updateUserInfoButtonActionPerformed(evt);
            }
        });

        jLabel4.setText("Enter 1 for Student, 2 for Graduate, and 3 for Graduate Coordinator");

        getUserInfoButton.setText("Get User Info");
        getUserInfoButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                getUserInfoButtonActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout StudentEditFrameLayout = new org.jdesktop.layout.GroupLayout(StudentEditFrame.getContentPane());
        StudentEditFrame.getContentPane().setLayout(StudentEditFrameLayout);
        StudentEditFrameLayout.setHorizontalGroup(
            StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(StudentEditFrameLayout.createSequentialGroup()
                .add(35, 35, 35)
                .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 81, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(getUserInfoButton)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(StudentEditFrameLayout.createSequentialGroup()
                        .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                            .add(StudentEditFrameLayout.createSequentialGroup()
                                .add(61, 61, 61)
                                .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                                    .add(jLabel2)
                                    .add(jLabel3)))
                            .add(StudentEditFrameLayout.createSequentialGroup()
                                .add(68, 68, 68)
                                .add(jLabel1)))
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                        .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                            .add(usernameBox)
                            .add(passwordBox)
                            .add(permissionsBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 89, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(updateUserInfoButton))
                    .add(jLabel4))
                .addContainerGap(123, Short.MAX_VALUE))
        );
        StudentEditFrameLayout.setVerticalGroup(
            StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(StudentEditFrameLayout.createSequentialGroup()
                .add(58, 58, 58)
                .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(StudentEditFrameLayout.createSequentialGroup()
                        .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel1)
                            .add(usernameBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel2)
                            .add(passwordBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                            .add(updateUserInfoButton))
                        .add(18, 18, 18)
                        .add(StudentEditFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                            .add(jLabel3)
                            .add(permissionsBox, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                        .add(18, 18, 18)
                        .add(jLabel4, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 14, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(getUserInfoButton)
                    .add(jScrollPane5, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(111, Short.MAX_VALUE))
        );

        editAnnouncementTextArea.setColumns(20);
        editAnnouncementTextArea.setLineWrap(true);
        editAnnouncementTextArea.setRows(5);
        editAnnouncementTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Edit Announcement"));
        jScrollPane6.setViewportView(editAnnouncementTextArea);

        btn_Submit.setText("Update");
        btn_Submit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btn_SubmitActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout editAnnouncementFrameLayout = new org.jdesktop.layout.GroupLayout(editAnnouncementFrame.getContentPane());
        editAnnouncementFrame.getContentPane().setLayout(editAnnouncementFrameLayout);
        editAnnouncementFrameLayout.setHorizontalGroup(
            editAnnouncementFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(editAnnouncementFrameLayout.createSequentialGroup()
                .add(35, 35, 35)
                .add(editAnnouncementFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(btn_Submit)
                    .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 506, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(38, Short.MAX_VALUE))
        );
        editAnnouncementFrameLayout.setVerticalGroup(
            editAnnouncementFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(editAnnouncementFrameLayout.createSequentialGroup()
                .add(28, 28, 28)
                .add(jScrollPane6, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 129, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
                .add(btn_Submit)
                .addContainerGap(24, Short.MAX_VALUE))
        );

        viewAvailability.setTitle("View Availability");
        viewAvailability.setAlwaysOnTop(true);
        viewAvailability.setMinimumSize(new java.awt.Dimension(317, 320));
        viewAvailability.setModalityType(java.awt.Dialog.ModalityType.APPLICATION_MODAL);
        viewAvailability.setName("viewAvailability");
        viewAvailability.setResizable(false);

        jLabel7.setText("Select Graduate Assistant:");

        select_Cmb.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        select_Cmb.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                select_CmbActionPerformed(evt);
            }
        });

        dayDropDown.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" }));
        dayDropDown.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dayDropDownActionPerformed(evt);
            }
        });

        jLabel8.setText("Hours available:");

        hoursList.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Item 1", "Item 2", "Item 3", "Item 4", "Item 5" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jScrollPane8.setViewportView(hoursList);

        org.jdesktop.layout.GroupLayout viewAvailabilityLayout = new org.jdesktop.layout.GroupLayout(viewAvailability.getContentPane());
        viewAvailability.getContentPane().setLayout(viewAvailabilityLayout);
        viewAvailabilityLayout.setHorizontalGroup(
            viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(viewAvailabilityLayout.createSequentialGroup()
                .addContainerGap()
                .add(viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(jLabel8)
                    .add(jLabel7))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(dayDropDown, 0, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .add(select_Cmb, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jScrollPane8))
                .add(0, 56, Short.MAX_VALUE))
        );
        viewAvailabilityLayout.setVerticalGroup(
            viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(viewAvailabilityLayout.createSequentialGroup()
                .addContainerGap()
                .add(viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
                    .add(jLabel7)
                    .add(select_Cmb, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                .add(18, 18, 18)
                .add(dayDropDown, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(viewAvailabilityLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(jScrollPane8, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 199, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                    .add(jLabel8))
                .addContainerGap(39, Short.MAX_VALUE))
        );

        viewAvailability.getAccessibleContext().setAccessibleName("");

        queRespFrame.setTitle("Reply to Query");

        viewQueRespTextArea.setColumns(20);
        viewQueRespTextArea.setEditable(false);
        viewQueRespTextArea.setLineWrap(true);
        viewQueRespTextArea.setRows(5);
        viewQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Query"));
        jScrollPane7.setViewportView(viewQueRespTextArea);

        submitQueRespTextArea.setColumns(20);
        submitQueRespTextArea.setRows(5);
        submitQueRespTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Response"));
        jScrollPane9.setViewportView(submitQueRespTextArea);

        submitQueRespBtn.setText("Submit");
        submitQueRespBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitQueRespBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout queRespFrameLayout = new org.jdesktop.layout.GroupLayout(queRespFrame.getContentPane());
        queRespFrame.getContentPane().setLayout(queRespFrameLayout);
        queRespFrameLayout.setHorizontalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(14, 14, 14)
                .add(queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING, false)
                    .add(jScrollPane9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 444, Short.MAX_VALUE)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, jScrollPane7)
                    .add(org.jdesktop.layout.GroupLayout.TRAILING, submitQueRespBtn))
                .addContainerGap(15, Short.MAX_VALUE))
        );
        queRespFrameLayout.setVerticalGroup(
            queRespFrameLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(queRespFrameLayout.createSequentialGroup()
                .add(10, 10, 10)
                .add(jScrollPane7, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 134, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                .add(18, 18, 18)
                .add(jScrollPane9, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 124, Short.MAX_VALUE)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitQueRespBtn)
                .addContainerGap())
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Help Desk - Coordinator");
        setName("Help Desk - Coordinator");

        submitBtn.setText("Submit");
        submitBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                submitBtnActionPerformed(evt);
            }
        });

        optionsPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Options"));

        stuRoleBtn.setText("Edit Student Role");
        stuRoleBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                stuRoleBtnActionPerformed(evt);
            }
        });

        rplyQueryBtn.setText("Reply to Query");
        rplyQueryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                rplyQueryBtnActionPerformed(evt);
            }
        });

        editQueryBtn.setText("Edit Query");
        editQueryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editQueryBtnActionPerformed(evt);
            }
        });

        deleteQueryBtn.setText("Delete Query");
        deleteQueryBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteQueryBtnActionPerformed(evt);
            }
        });

        editAnnounceBtn.setText("Edit Announcement");
        editAnnounceBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                editAnnounceBtnActionPerformed(evt);
            }
        });

        deleteAnnounceBtn.setText("Delete Announcement");
        deleteAnnounceBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                deleteAnnounceBtnActionPerformed(evt);
            }
        });

        viewAvaBtn.setText("View Grad. Availability");
        viewAvaBtn.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                viewAvaBtnActionPerformed(evt);
            }
        });

        org.jdesktop.layout.GroupLayout optionsPanelLayout = new org.jdesktop.layout.GroupLayout(optionsPanel);
        optionsPanel.setLayout(optionsPanelLayout);
        optionsPanelLayout.setHorizontalGroup(
            optionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(optionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(viewAvaBtn)
                    .add(optionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, stuRoleBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, rplyQueryBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, editQueryBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, deleteQueryBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, editAnnounceBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .add(org.jdesktop.layout.GroupLayout.LEADING, deleteAnnounceBtn, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        optionsPanelLayout.setVerticalGroup(
            optionsPanelLayout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(optionsPanelLayout.createSequentialGroup()
                .addContainerGap()
                .add(stuRoleBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(rplyQueryBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(editQueryBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(deleteQueryBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(editAnnounceBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(deleteAnnounceBtn)
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(viewAvaBtn)
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        submissionTextArea.setColumns(20);
        submissionTextArea.setLineWrap(true);
        submissionTextArea.setRows(5);
        submissionTextArea.setBorder(javax.swing.BorderFactory.createTitledBorder("Post Announcement"));
        jScrollPane2.setViewportView(submissionTextArea);

        announcementsScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Announcements"));

        announcementModel = new MyTableModel();
        announcementsTable.setModel(announcementModel);
        announcementsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        announcementsTable.setAutoscrolls(false);
        announcementsTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        announcementsTable.getTableHeader().setReorderingAllowed(false);
        announcementsScrollPane.setViewportView(announcementsTable);
        announcementsTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        updateAnnouncement();

        queriesScrollPane.setBorder(javax.swing.BorderFactory.createTitledBorder("Queries"));

        queryModel = new MyTableModel();//DefaultTableModel();
        queries = DatabaseInteraction.getAllQueries();
        queryData = new Object[queries.length][2];
        queryModel.addColumn("User");
        queryModel.addColumn("Query");
        for(int i=0;i<queries.length;i++){
            queryData[i][0] = queries[i].get("createdby");
            queryData[i][1] = queries[i].get("content");
        }
        queryModel.setDataVector(queryData, new Object[]{"User","Query"});
        queriesTable.setModel(queryModel);
        queriesTable.setAutoscrolls(false);
        queriesTable.setColumnSelectionAllowed(false);
        queriesTable.setFocusable(false);
        queriesTable.setMaximumSize(new java.awt.Dimension(1000, 500));
        queriesTable.setMinimumSize(new java.awt.Dimension(500, 100));
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);

        javax.swing.table.TableColumn col = queriesTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = queriesTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
        queriesScrollPane.setViewportView(queriesTable);
        queriesTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);

        org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(37, 37, 37)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING)
                    .add(submitBtn)
                    .add(layout.createSequentialGroup()
                        .add(optionsPanel, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .add(18, 18, 18)
                        .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.TRAILING, false)
                            .add(org.jdesktop.layout.GroupLayout.LEADING, jScrollPane2)
                            .add(announcementsScrollPane)
                            .add(queriesScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 481, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
            .add(layout.createSequentialGroup()
                .add(17, 17, 17)
                .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
                    .add(layout.createSequentialGroup()
                        .add(announcementsScrollPane, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 156, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(queriesScrollPane, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 170, Short.MAX_VALUE)
                        .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                        .add(jScrollPane2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
                    .add(optionsPanel, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
                .add(submitBtn)
                .addContainerGap())
        );

        getAccessibleContext().setAccessibleName("Help Desk - Coordinator");

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void stuRoleBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_stuRoleBtnActionPerformed
        updateUserList();
        StudentEditFrame.setSize(650, 300);
        StudentEditFrame.setVisible(true);
    }//GEN-LAST:event_stuRoleBtnActionPerformed

    private void rplyQueryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_rplyQueryBtnActionPerformed
        int index = queriesTable.getSelectedRow();
        if (queriesTable.isRowSelected(index)) {
            String content = queries[index].get("content").toString();
            String username = queries[index].get("createdBy").toString();
            String responses = queries[index].get("responses").toString();
            if (responses.length() > 0) {
                responses += "\n";
            }
            viewQueRespTextArea.setText(username + ": " + content);
            submitQueRespTextArea.setText(responses + currentUser + ": ");
            queRespFrame.setSize(500, 350);
            queRespFrame.setVisible(true);

        }
    }//GEN-LAST:event_rplyQueryBtnActionPerformed

    private void viewAvaBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_viewAvaBtnActionPerformed
        Availability gradAvail;
        gradUsers = DatabaseInteraction.getUsers(2);
        gradUsernames = new String[gradUsers.length];

        for (int i = 0; i < gradUsers.length; i++) {
            gradUsernames[i] = gradUsers[i].getUserName();
        }
        select_Cmb.setModel(new javax.swing.DefaultComboBoxModel(gradUsernames));
        select_Cmb.setSelectedIndex(0);
        gradAvail = DatabaseInteraction.getAvailability(gradUsernames[0]);
        updateDaySelected(gradAvail, 0);
        viewAvailability.setSize(417, 320);
        viewAvailability.setVisible(true);

    }//GEN-LAST:event_viewAvaBtnActionPerformed
    private void updateDaySelected(Availability gradAvail, int index) {
        ArrayList<String> hours = new ArrayList<String>();
        int j = 0;
        for (int i = 0; i < 24; i++) {
            boolean hour = gradAvail.getDay(index).getTimeslot(i);
            if (hour) {
                if (i == 0)                 {
                    hours.add(" 12am to 1am.");
                } else if (i == 11) 
                {
                    hours.add(" 11am to 12pm.");
                } else if (i == 23) 
                {
                    hours.add(" 11pm to 12am.");
                } else if (i == 12) 
                {
                    hours.add(" 12pm to 1pm.");
                } else if (i < 12)
                {
                    hours.add(" " + i + "am to " + (i + 1) + "am.");
                } else
                {
                    hours.add(" " + (i - 12) + "pm to " + (i - 11) + "pm.");
                }
                j++;
            }
        }
        hoursList.setListData(hours.toArray(new String[hours.size()]));
    }
    private void editQueryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editQueryBtnActionPerformed
        if (queriesTable.isRowSelected(queriesTable.getSelectedRow())) {
            editQueryFrame.setSize(600, 300);
            editQueryFrame.setVisible(true);
            String content = queries[queriesTable.getSelectedRow()].get("content").toString();
            editQueryTextArea.setText("[EDITED] " + content);
        }
    }//GEN-LAST:event_editQueryBtnActionPerformed

    private void submitEditQueryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitEditQueryBtnActionPerformed
        queries[queriesTable.getSelectedRow()].updateItem("content", editQueryTextArea.getText());
        int id = Integer.parseInt(queries[queriesTable.getSelectedRow()].get("id").toString());
        DatabaseInteraction.deleteQuery(id);
        DatabaseInteraction.postQuery(queries[queriesTable.getSelectedRow()]);
        updateQueries();
        editQueryFrame.dispose();
    }//GEN-LAST:event_submitEditQueryBtnActionPerformed

    private void deleteQueryBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteQueryBtnActionPerformed
        if (queriesTable.isRowSelected(queriesTable.getSelectedRow())) {
            int id = Integer.parseInt(queries[queriesTable.getSelectedRow()].get("id").toString());
            DatabaseInteraction.deleteQuery(id);
            updateQueries();
        }
    }//GEN-LAST:event_deleteQueryBtnActionPerformed

    private void getUserInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_getUserInfoButtonActionPerformed
        currentUsername = users[UsersList.getSelectedIndex()].getUserName();
        usernameBox.setText(currentUsername);
        passwordBox.setText(users[UsersList.getSelectedIndex()].getPassword());
        permissionsBox.setText(Integer.toString(users[UsersList.getSelectedIndex()].getPermissions()));
    }//GEN-LAST:event_getUserInfoButtonActionPerformed

    private void updateUserInfoButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_updateUserInfoButtonActionPerformed
        EditUsers.updateUser(currentUsername, usernameBox.getText(), passwordBox.getText(),
                Integer.parseInt(permissionsBox.getText()));
        updateUserList();
    }//GEN-LAST:event_updateUserInfoButtonActionPerformed

    private void submitBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitBtnActionPerformed
        String createdby, content;
        if (!submissionTextArea.getText().equals("")) {
            createdby = currentUser;
            content = submissionTextArea.getText();
            Announcement announce = new Announcement(createdby, content);
            DatabaseInteraction.postAnnouncement(announce);
            updateAnnouncement();
            resetForm();
        }

    }//GEN-LAST:event_submitBtnActionPerformed

    private void editAnnounceBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editAnnounceBtnActionPerformed

        if (announcementsTable.isRowSelected(announcementsTable.getSelectedRow())) {
            editAnnouncementFrame.setSize(600, 300);
            editAnnouncementFrame.setVisible(true);
            String content = announcements[announcementsTable.getSelectedRow()].getContent();
            editAnnouncementTextArea.setText("[EDITED] " + content);
        }
    }//GEN-LAST:event_editAnnounceBtnActionPerformed

    private void btn_SubmitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btn_SubmitActionPerformed
        announcements[announcementsTable.getSelectedRow()].setContent(editAnnouncementTextArea.getText());
        int id = announcements[announcementsTable.getSelectedRow()].getId();
        DatabaseInteraction.editAnnouncment(id, "content", editAnnouncementTextArea.getText());
        updateAnnouncement();
        editAnnouncementFrame.dispose();
    }//GEN-LAST:event_btn_SubmitActionPerformed

    private void deleteAnnounceBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_deleteAnnounceBtnActionPerformed
        if (announcementsTable.isRowSelected(announcementsTable.getSelectedRow())) {
            int id = announcements[announcementsTable.getSelectedRow()].getId();
            DatabaseInteraction.deleteAnnouncement(id);
            updateAnnouncement();
        }
    }//GEN-LAST:event_deleteAnnounceBtnActionPerformed

    private void dayDropDownActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dayDropDownActionPerformed
        int username = select_Cmb.getSelectedIndex();
        int day = dayDropDown.getSelectedIndex();
        Availability gradAvail = DatabaseInteraction.getAvailability(gradUsernames[username]);
        updateDaySelected(gradAvail, day);
    }//GEN-LAST:event_dayDropDownActionPerformed

    private void select_CmbActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_select_CmbActionPerformed
        int username = select_Cmb.getSelectedIndex();
        int day = dayDropDown.getSelectedIndex();
        Availability gradAvail = DatabaseInteraction.getAvailability(gradUsernames[username]);
        updateDaySelected(gradAvail, day);
    }//GEN-LAST:event_select_CmbActionPerformed

    private void submitQueRespBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_submitQueRespBtnActionPerformed
        int id = Integer.parseInt(queries[queriesTable.getSelectedRow()].get("id").toString());
        DatabaseInteraction.editQuery(id, "responses", submitQueRespTextArea.getText());
        updateQueries();
        queRespFrame.dispose();
    }//GEN-LAST:event_submitQueRespBtnActionPerformed
    private void resetForm() {
        submissionTextArea.setText("");
    }

    public void updateUserList() {
        users = EditUsers.getUsers();
        String[] usernames = new String[users.length];
        for (int i = 0; i < users.length; i++) {
            usernames[i] = users[i].getUserName();
        }
        UsersList.setListData(usernames);
        if (firstRun) {
            UsersList.setSelectedIndex(0);
            firstRun = false;
        }
    }

    public void updateUserInfo(String username, String password, int permissions) {
        User user = new User(usernameBox.getText(), passwordBox.getText(), Integer.parseInt(permissionsBox.getText()));
        EditUsers.updateUser(currentUsername, user);
        updateUserList();
    }

    private void updateQueries() {
        queries = DatabaseInteraction.getAllQueries();
        queryData = new Object[queries.length][2];
        for (int i = 0; i < queries.length; i++) {
            queryData[i][0] = queries[i].get("createdby");
            queryData[i][1] = queries[i].get("content");
        }
        queryModel.setDataVector(queryData, new Object[]{"User", "Query"});
        queriesTable.setModel(queryModel);
        queriesTable.setColumnSelectionAllowed(false);
        queriesTable.setMaximumSize(new java.awt.Dimension(1000, 500));
        queriesTable.setMinimumSize(new java.awt.Dimension(500, 100));
        queriesTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        queriesTable.getTableHeader().setReorderingAllowed(false);
        queriesTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = queriesTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = queriesTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
        queriesScrollPane.setViewportView(queriesTable);
        queriesTable.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
    }

    private void updateAnnouncement() {
        announcements = DatabaseInteraction.getAllAnnouncements();
        announcementData = new Object[announcements.length][2];
        for (int i = 0; i < announcements.length; i++) {
            announcementData[i][0] = announcements[i].getCreateBy();
            announcementData[i][1] = announcements[i].getContent();
        }
        announcementModel.setDataVector(announcementData, new Object[]{"User", "Announcment"});
        announcementsTable.setModel(announcementModel);
        announcementsTable.getTableHeader().setReorderingAllowed(false);
        announcementsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        javax.swing.table.TableColumn col = announcementsTable.getColumnModel().getColumn(0);
        col.setPreferredWidth(100);
        javax.swing.table.TableColumn col2 = announcementsTable.getColumnModel().getColumn(1);
        col2.setPreferredWidth(1000);
    }
    private boolean firstRun = true;
    String[] gradUsernames;
    User[] users;
    User[] gradUsers;
    private String currentUsername;//used for the changing permissions dialog
    private String currentUser;//passed in current user logged in
    MyTableModel queryModel;
    MyTableModel announcementModel;
    Query[] queries;
    Announcement[] announcements;
    Object[][] queryData;
    Object[][] announcementData;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JFrame StudentEditFrame;
    private javax.swing.JList UsersList;
    private javax.swing.JScrollPane announcementsScrollPane;
    private javax.swing.JTable announcementsTable;
    private javax.swing.JButton btn_Submit;
    private javax.swing.JComboBox dayDropDown;
    private javax.swing.JButton deleteAnnounceBtn;
    private javax.swing.JButton deleteQueryBtn;
    private javax.swing.JButton editAnnounceBtn;
    private javax.swing.JFrame editAnnouncementFrame;
    private javax.swing.JTextArea editAnnouncementTextArea;
    private javax.swing.JButton editQueryBtn;
    private javax.swing.JFrame editQueryFrame;
    private javax.swing.JTextArea editQueryTextArea;
    private javax.swing.JButton getUserInfoButton;
    private javax.swing.JList hoursList;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JPanel optionsPanel;
    private javax.swing.JTextField passwordBox;
    private javax.swing.JTextField permissionsBox;
    private javax.swing.JDialog queRespFrame;
    private javax.swing.JScrollPane queriesScrollPane;
    private javax.swing.JTable queriesTable;
    private javax.swing.JButton rplyQueryBtn;
    private javax.swing.JComboBox select_Cmb;
    private javax.swing.JButton stuRoleBtn;
    private javax.swing.JTextArea submissionTextArea;
    private javax.swing.JButton submitBtn;
    private javax.swing.JButton submitEditQueryBtn;
    private javax.swing.JToggleButton submitQueRespBtn;
    private javax.swing.JTextArea submitQueRespTextArea;
    private javax.swing.JButton updateUserInfoButton;
    private javax.swing.JTextField usernameBox;
    private javax.swing.JButton viewAvaBtn;
    private javax.swing.JDialog viewAvailability;
    private javax.swing.JTextArea viewQueRespTextArea;
    // End of variables declaration//GEN-END:variables
}
